package org.presstrack
{
	import org.presstrack.service.CrudService;
	import flash.net.Responder;	
	import mx.utils.ObjectUtil;
	
	[RemoteClass(alias="org.presstrack.ContactClass")]
	
	[Bindable]
	public class ContactClass
	{
		public var idcontact:int;
		public var user:int;
		public var type:int;
		public var body:String;
		
		public function ContactClass()
		{
		}
		
		public function setFromObject(ob:Object):void {
			if (ob.hasOwnProperty("idcontact"))
				idcontact = int(ob.idcontact);
				
			if (ob.hasOwnProperty("user"))
				user = int(ob.user);
				
			if (ob.hasOwnProperty("type"))
				type = int(ob.type);
				
			if (ob.hasOwnProperty("body"))
				body = ob.body.toString();
		}
		
		public function updateContact(_body:String, resFunc:Function = null, faultFunc:Function = null):void 
		{
			_body = _body.replace('\r','');
			CrudService.crud.srv.call("PressTrack.UpdateUserContact", new Responder(onResult, onFault), idcontact, _body);
			
			function onResult(res:String) : void 
			{
				if (res == 'successful') {
					body = _body;
					CrudService.arCustomer.refresh();
					if (resFunc != null) resFunc();
				}
				else	
					faultFunc(res);			
			}
			
			function onFault(e:Object) : void {
				faultFunc(ObjectUtil.toString(e));
			}
		}
	}
}